const hospitalMod = require('../model/hospitalMod.js')
const {
  nowTime
} = require('../utils/formattime')

// 该层处理数据库参数
const hospitalServ = {
  hspInfoServ:async () => {
    let res = await hospitalMod.hspInfoMod()
    let {max_num , appointment_num} = res[0]
    let h_status = 0 // 0 预约未满，1 预约已满
    if(appointment_num >= max_num ) h_status = 1
    res[0].h_status = h_status
    // console.log(res);
    return res
  },
  appoimentHspServ : async (data) => {
    await hospitalMod.appoimentHspMod(data)
  },
  appoimentStatusServ : async (data) => {
   const res =  await hospitalMod.appoimentStatusMod(data)
   let status = 0
   if(res.length !== 0) {
      if(res[0].ctime.slice(0,10) === nowTime().slice(0,10)){
        status = 1
      }
   }
   return {status}
  },
  cancleAppoiServ: async (data) => {
    await hospitalMod.cancleAppoiMod(data)
  },
  editeHosiptalWebServ:async (data) => {
    await hospitalMod.editeHosiptalWebMod(data)
  }
}

module.exports = hospitalServ